package com.wxzz.elearing.course.api.server;


import com.alibaba.fastjson.JSONObject;
import com.wxzz.elearing.course.service.ICurriculumService;
import com.wxzz.elearing.course.service.IWxUserCurriculumService;
import com.wxzz.elearing.course.vo.StudyTimeVo;
import com.wxzz.elearning.common.dto.FeignStudyTimeDto;
import com.wxzz.elearning.common.vo.ReturnVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/curriculum-api")
public class CurriculumApi {

    @Autowired
    private ICurriculumService curriculumService;

    /**
     * 企业购买课程支付成功确认
     *
     * @return
     */
    @RequestMapping(value = "/copyNewCurriculum/{enterpriseId}/{curriculumId}/{orderId}", method = RequestMethod.POST)
    public void copyNewCurriculum(@PathVariable Long enterpriseId, @PathVariable Long curriculumId, @PathVariable Long orderId) {
        curriculumService.copyNewCurriculum(enterpriseId, curriculumId, orderId);
    }

    /**
     * 根据微信用户id查询学习课程数据
     *
     * @param wxUserId
     * @return
     */
    @RequestMapping(value = "/selectWxUserCurriculumDataByWxUserId/{wxUserId}", method = RequestMethod.POST)
    public ReturnVO<String> selectWxUserCurriculumDataByWxUserId(@PathVariable Long wxUserId) {
        return curriculumService.selectWxUserCurriculumDataByWxUserId(wxUserId);
    }

    @Autowired
    private IWxUserCurriculumService wxUserCurriculumService;

    /**
     * 根据讲师id查询总讲数和参与学习人数
     *
     * @param docentId
     * @return
     */
    @RequestMapping(value = "/selectDocentById/{docentId}", method = RequestMethod.POST)
    public ReturnVO<String> selectDocentById(@PathVariable Long docentId) {
        return wxUserCurriculumService.selectDocentById(docentId);
    }

    /**
     * 根据订单id查询用户购买的课程信息
     *
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/selectCurriculumByOrderId/{orderId}", method = RequestMethod.POST)
    public ReturnVO<JSONObject> selectCurriculumByOrderId(@PathVariable Long orderId) {
        return wxUserCurriculumService.selectCurriculumByOrderId(orderId);
    }

    /**
     * 根据订单id查询企业购买的课程信息
     *
     * @param orderId
     * @return
     */
    @RequestMapping(value = "/selectCurriculum4EnterpriseByOrderId/{orderId}", method = RequestMethod.POST)
    public ReturnVO<JSONObject> selectCurriculum4EnterpriseByOrderId(@PathVariable Long orderId) {
        return curriculumService.selectCurriculum4EnterpriseByOrderId(orderId);
    }

    /**
     * 查询课程总数
     *
     * @return
     */
    @RequestMapping(value = "/countByCourse", method = RequestMethod.POST)
    public Integer countByCourse() {
        return curriculumService.countByCourse();
    }

    /**
     * 查询企业的学习时长
     *
     * @param enterpriseId
     * @return
     */
    @RequestMapping(value = "/selectFeignStudyTimeDto/{enterpriseId}", method = RequestMethod.POST)
    public FeignStudyTimeDto selectFeignStudyTimeDto(@PathVariable Long enterpriseId) {
        return curriculumService.selectFeignStudyTimeDto(enterpriseId);
    }

    /**
     * 查询企业的课程数量
     *
     * @param enterpriseId
     * @return
     */
    @RequestMapping(value = "/selectCountByEnterpriseId/{enterpriseId}", method = RequestMethod.POST)
    public Integer selectCountByEnterpriseId(@PathVariable Long enterpriseId) {
        return curriculumService.selectCountByEnterpriseId(enterpriseId);
    }

}
